local hx__kongbu = fk.CreateSkill {
  name = "hx__kongbu",
}

local HX = require "packages/huixiangkill/hxfs"

hx__kongbu:addEffect("active", {
  name = "hx__kongbu",
  anim_type = "drawcard",
  card_num = 2,
  target_num = 0,
  prompt = "#hx__kongbu",
  can_use = function(self, player)
    return player:usedSkillTimes(hx__kongbu.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected < 2 and not player:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, hx__kongbu.name, player, player)
    if player.dead then return end
    local card = room:getCardsFromPileByRule("slash", 1, "allPiles")
    if #card > 0 then
      room:moveCards({
        ids = card,
        to = player,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player,
        skillName = hx__kongbu.name,
      })
      room:setCardMark(Fk:getCardById(card[1]), "@@hx__kongbu-turn", 1)
    end
  end,
})

hx__kongbu:addEffect("targetmod", {
  name = "#hx__kongbu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@hx__kongbu-turn") > 0
  end,
})

hx__kongbu:addEffect(fk.Damage, {
  anim_type = "special",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__kongbu.name) and data.card and data.card.trueName == "slash" and
      data.card:getMark("@@hx__kongbu-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    HX.SetSkillsTimes(room,player, 0)
  end,
})

return hx__kongbu